package com.project.class3_30;

public class MainThread {

    public static void main(String[] args) {
        OneThread one = new OneThread();
        //启动线程，线程启动后，会执行run()
        one.start();

        //创建线程，传入Runnable实现类对象。
        //当线程启动时，会执行Runnable实现类的run()
        Thread th = new Thread(new TwoThread());
        th.start();

        for(int i=0;i<10;i++){
                System.out.println(i);

                try {
                    //线程休眠1000毫秒
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
        }
    }
}

class OneThread extends Thread{
    @Override
    public void run() {
        for(int i=10;i<20;i++){
            System.out.println(i);
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

class TwoThread implements Runnable{

    @Override
    public void run() {
        for(int i=20;i<30;i++){
            System.out.println(i);

            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
